package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.CacheUtils;
import com.ruoyi.system.domain.UserDataSource;
import com.ruoyi.system.mapper.UserDataSourceMapper;
import com.ruoyi.system.service.UserDataSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.ruoyi.system.utils.DictUtils.getCacheName;

@Service
public class UserDataSourceServiceImpl implements UserDataSourceService {

    @Autowired
    private UserDataSourceMapper userDataSourceMapper;

    @Override
    public List<UserDataSource> selectDataSourceAll(UserDataSource userDataSource) {
        return userDataSourceMapper.selectDataSourceAll(userDataSource);
    }

    @Override
    public int insertDataSourceInfo(UserDataSource userDataSource) {
        return userDataSourceMapper.insertDataSourceInfo(userDataSource);
    }

    @Override
    public int deleteDataSourceByIds(String[] ids) {
        int i = userDataSourceMapper.deleteDataSourceByIds(ids);
        if(i>0){//删除成功后清除缓存
            CacheUtils.removeAll(getCacheName());
        }
        return i;
    }

    @Override
    public int updateDataSourceById(UserDataSource userDataSource) {
        return userDataSourceMapper.updateDataSourceById(userDataSource);
    }

    @Override
    public boolean checkDataSourceNameUnique(UserDataSource userDataSource) {
        return userDataSourceMapper.checkDataSourceNameUnique(userDataSource)<=0;
    }
}
